﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    public class CtHD_DAL:ketnoi
    {
        public bool cthd_them(VO.CtHD_VO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_Insert", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@MaHD", data.MaHD));
                    dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                    dbCmd.Parameters.Add(new SqlParameter("@MaS", data.MaS));
                    dbCmd.Parameters.Add(new SqlParameter("@SL", data.SL));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool cthd_sua(VO.CtHD_VO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", data.MaHD));
                dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@MaS", data.MaS));
                dbCmd.Parameters.Add(new SqlParameter("@SL", data.SL));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public DataTable cthd_mahd()
        {
            DataTable dt = new DataTable();

            using (SqlCommand dbCmd = new SqlCommand("ct_hd", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable cthd_mas()
        {
            DataTable dt = new DataTable();

            using (SqlCommand dbCmd = new SqlCommand("cthd_mas", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable timkiem_mas(string MaS)
        {
            DataTable dt = new DataTable();

            using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_GetByMaS", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.Parameters.Add(new SqlParameter("@MaS", MaS));
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable timkiem_maHD(string MaHD)
        {
            DataTable dt = new DataTable();

            using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_GetByMaHD", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", MaHD));
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable cthd_xem()
        {
            DataTable dt = new DataTable();
            
            using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_SelectAll", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public bool cthd_xoa(string MaHD)
        {
            using (SqlCommand dbCmd = new SqlCommand("tblCthoadon_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", MaHD));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
